package com.zhouke.certificate.exception;

import com.zhouke.certificate.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常处理类， 当后端出现未处理的异常时，对自定义异常进行处理，向前端返回异常数据
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(ServiceException.class)
    @ResponseBody
    public Result  handle(ServiceException se){
        return Result.error(se.getCode(),se.getMessage());
    }
}
